route.js 709 B

12345678910111213141516171819202122232425262728
  1. import { NextResponse } from "next/server";
  2. import { listMonths } from "@/lib/storage";
  3. export async function GET(request, ctx) {
  4. const { branch, year } = await ctx.params;
  5. console.log("[/api/branches/[branch]/[year]/months] params:", {
  6. branch,
  7. year,
  8. });
  9. if (!branch || !year) {
  10. return NextResponse.json(
  11. { error: "branch oder year fehlt" },
  12. { status: 400 }
  13. );
  14. }
  15. try {
  16. const months = await listMonths(branch, year);
  17. return NextResponse.json({ branch, year, months });
  18. } catch (error) {
  19. console.error("[/api/branches/[branch]/[year]/months] Fehler:", error);
  20. return NextResponse.json(
  21. { error: "Fehler beim Lesen der Monate: " + error.message },
  22. { status: 500 }
  23. );
  24. }
  25. }